package com.itheima.controller;

import com.itheima.common.AliOSSUtils;
import com.itheima.common.R;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

@RestController
@Slf4j
@RequestMapping("/upload")
public class UploadController {
    @Autowired
    AliOSSUtils aliOSSUtils;
    @PostMapping
    @SneakyThrows//抑制异常
    public R upload(MultipartFile file) {
        log.info("文件上传：{}", file);
//        InputStream inputStream = file.getInputStream();
        String upload = aliOSSUtils.upload(file);
        return R.ok(upload);
    }
}
